<template>
	<view class="password-content">
		<view class="form-box">
			<u--form labelPosition="left" :model="passwordForm.data" :rules="passwordForm.rule" ref="passwordFormRef">
				<u-form-item label="手机号" prop="cellphone" borderBottom labelWidth='70'>
					<view class="">
						{{ passwordForm.data.cellphone_secret }}
					</view>
				</u-form-item>
				<u-form-item label="验证码" labelWidth='70' prop="code" borderBottom>
					<u-input v-model="passwordForm.data.code" border="none" customStyle="height:56rpx" maxlength='6'
						placeholder="请输入验证码" type='number'></u-input>
					<template v-slot:right>
						<view @click="sendSms">
							<sms ref="smsC"></sms>
						</view>
					</template>
				</u-form-item>
				<u-form-item label="密码" prop="password" borderBottom labelWidth='70'>
					<u--input v-model="passwordForm.data.password" border="none" placeholder="请输入密码"
						type="password"></u--input>
				</u-form-item>
				<u-form-item label="确认密码" prop="password_confirmation" borderBottom labelWidth='70'>
					<u--input v-model="passwordForm.data.password_confirmation" border="none" type="password"
						placeholder="再次输入密码"></u--input>
				</u-form-item>
				<view class="pass-tip">注：密码需字母与数字组合，最少6位</view>
			</u--form>
		</view>
		<view class=" button">
			<u-button type="primary" text="确定" class="custom-style" @click="passwordForm.submit"></u-button>
		</view>
	</view>
</template>
<script setup>
	import {
		ref
	} from 'vue'
	import {
		customStyle,
		customStyle1
	} from "../../../../utils/style";
	import {
		onShow,
		onUnload
	} from "@dcloudio/uni-app";
	import {
		sms
	} from '@/components/sms.vue'
	import {
		goNav
	} from "../../../../utils/common";
	import {
		passwordForm
	} from "../../../../utils/login";
	import {
		resetPassword
	} from "../../../../api/module/mine";
	const smsC = ref();
	const passwordFormRef = ref(null);
	passwordForm.init = {
		callback: function() {
			passwordFormRef.value.validate().then(validate => {
				if (validate) {
					resetPassword(passwordForm.data).then(res => {
						uni.setStorageSync("token", '')
						uni.setStorageSync("userInfo", null)
						goNav('/pages/alogin/index');
					})
				}
			})
		}
	}
	onShow(() => {
		passwordForm.reset();
		if (!uni.getStorageSync("userInfo")) {
			goNav('/pages/alogin/index');
			return;
		}
		passwordForm.data.cellphone = uni.getStorageSync("userInfo").cellphone
		passwordForm.data.cellphone_secret = uni.getStorageSync("userInfo").cellphone_secret
	})
	const sendSms = () => {
		smsC.value.send({
			phone: passwordForm.data.cellphone,
			type: "reset_password",
		})
	}
	onUnload(() => {

	})
</script>
<style lang="less" src="/static/css/my/password.scss"></style>
